** Data reading and variable selection from raw data
** POLPAN (Polish Panel Survey) (the 1988 wave)


** 01. Reading data **

cap log close
clear all
set more off
cd /*insert you work directory here*/
use /*read your data here*/


** 02. Consructing year and country variables **

ge year=1988
lab var year "survey year"

ge country=616
lab var country "ISO country code"
//Poland: 616 (see "ISO Country Codes.pdf) 


** 03. ID variables **

*ge pid=polpanid
ge pid=_n
lab var pid "person id"


** 04. Basic Demographics (Sex and Age/birth year) **

rename gender sex 
lab var sex "respondent sex"

rename yrbirth birthyr
lab var birthyr "year of birth"

ge age=1988-birthyr
lab var age "age"


** 05. Siblings **
//question: how many child did your father have (including the respondent)
ge nsibs=z39-1
lab var nsibs "number of siblings"
//number of brothers/sisters & birth order not available


** 06. Own education **

//highest year of school attended
rename z134last educ
lab var educ "respondent's last education attended"
//information on whether the respondent has completed the highest level of education reported is incomplete therefore cannot use


** 07. Parents' education: Father and/or Mother **

//only father's highest level of education is available, no mother information
rename z38 faeduc
lab var faeduc "father's education"


** 08. Own occupation **
//current job
rename z02skz occ
lab var occ "respondent current occupation in SKZ code"

rename z09 position
lab var position "whether respondent is in managerial/supervisory position_current job"

rename z09a supsize
replace supsize=0 if supsize<1 | supsize>4000
lab var supsize "number of people respondent supervises_current job"

rename z04a orgtype
lab var orgtype "respondent firm type_current job"

rename z04kgn ind
lab var ind "respondent industry in KGN code 1985_current job"

//first job
rename z14a_skz firstocc
lab var firstocc "respondent first occupation in SKZ code"

rename z14c firstown
lab var firstown "did firm belong to the respondent or the respondent family_first job"


** 09. Parents' occupation **

//no mother information
//father's first employment
rename z45skz fafirstocc
lab var fafirstocc "father first occpation in SKZ code"

rename z45man fafirstpo
lab var fafirstpo "father managerial position at first job"
lab def position 0 "not in managerial position" 1 "general director" 2 "deputy director"
lab val fafirstpo position

//father's employment when respondent was 14
rename z44a_skz faocc14
lab var faocc14 "father occupation in SKZ code when respondent was 14"

rename z44c faown14
lab var faown14 "did father work in family owned company when respondent was 14"

rename z44b fapo14
lab var fapo14 "father managerial position when respondent was 14"
lab val fapo14 position

//father's employment at respondent's age
rename z53skz faoccr
lab var faoccr "father occpation at respondent's age in SKZ code"

rename z53own faownr
lab var faownr "did father work in family owned company at respondent's age"

rename z53man fapor
lab var fapor "father managerial position at respondent's age"
lab val fapor position


** 10. Tabulate the Identified Variables **

log using /*insert you work directory here*/, replace text

** Data reading and variable selection from raw data
** POLPAN (Polish Panel Survey) (the 1988 wave)

** Sex **
tab sex

** Age, Birth Year **
sum age birthyr, d

** Siblings **
sum nsibs, d

** R's Own Education **
tab1 educ

** Parental Education **
tab1 faeduc 

** R's Own Occupation **
tab1 occ position supsize orgtype ind firstocc firstown

** Parental Occupation **
tab1 fafirstocc fafirstpo faocc14 faown14 fapo14 faoccr faownr fapor

log close

** 11. Keep the identified variables only

keep year country pid sex age birthyr ///
	 nsibs educ faeduc ///
	 occ position supsize orgtype ind firstocc firstown ///
	 fafirstocc fafirstpo faocc14 faown14 fapo14 faoccr faownr fapor
	 

** 12. Save the Data File **

saveold /*insert you work directory here*/, replace



** 13. Homoginising education **
** Own Education **
rename educ educ_cat

ge educ_yrs=6 if educ_cat==1
replace educ_yrs=6 if educ_cat==2
replace educ_yrs=9 if educ_cat==3
replace educ_yrs=10 if educ_cat==4
replace educ_yrs=12 if educ_cat==5
replace educ_yrs=12 if educ_cat==6
replace educ_yrs=14 if educ_cat==7
replace educ_yrs=14 if educ_cat==8
replace educ_yrs=17 if educ_cat==9
replace educ_yrs=20 if educ_cat==10
lab var educ_yrs "respondent highest education in years"

ge educ_ISCED=100 if educ_cat==2
replace educ_ISCED=244 if educ_cat==3
replace educ_ISCED=350 if educ_cat==5
replace educ_ISCED=340 if educ_cat==6
replace educ_ISCED=500 if educ_cat==7
replace educ_ISCED=600 if educ_cat==9
replace educ_ISCED=700 if educ_cat==10
lab var educ_ISCED "respondent highest education in ISCED 2011 code"

** Parents Education **
//mother's education is not available

ge faeduc_flag=1 

rename faeduc faeduc_cat

ge faeduc_yrs=6 if faeduc_cat==1
replace faeduc_yrs=6 if faeduc_cat==2
replace faeduc_yrs=9 if faeduc_cat==3
replace faeduc_yrs=10 if faeduc_cat==4
replace faeduc_yrs=12 if faeduc_cat==5
replace faeduc_yrs=12 if faeduc_cat==6
replace faeduc_yrs=14 if faeduc_cat==7
replace faeduc_yrs=14 if faeduc_cat==8
replace faeduc_yrs=17 if faeduc_cat==9
replace faeduc_yrs=20 if faeduc_cat==10
lab var faeduc_yrs "father's education in years"

ge faeduc_ISCED=020 if faeduc_cat==1
replace faeduc_ISCED=100 if faeduc_cat==2
replace faeduc_ISCED=244 if faeduc_cat==3
replace faeduc_ISCED=244 if faeduc_cat==4
replace faeduc_ISCED=350 if faeduc_cat==5
replace faeduc_ISCED=340 if faeduc_cat==6
replace faeduc_ISCED=500 if faeduc_cat==7
replace faeduc_ISCED=500 if faeduc_cat==8
replace faeduc_ISCED=600 if faeduc_cat==9
replace faeduc_ISCED=700 if faeduc_cat==10
lab var faeduc_ISCED "father highest education in ISCED 2011 code"


** 14. Homoginising sibling **
//cutoff
ge nsibs_flag=99
lab var nsibs_flag "cutoff of total number of siblings"

lab def nsib_flag 99 "no cutoff"
lab val nsibs_flag nsib_flag

//number of brothers/sisters not available


** 15. Tab Education and Sibling Variables **
tab1 sex age birthyr
tab1 educ_cat educ_yrs faeduc_cat faeduc_yrs faeduc_flag 
tab1 nsibs nsibs_flag


** 16. Save the Data File **

saveold /*insert you work directory here*/, replace
